package utils

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type Builder struct {
	resp Response
}

func NewBuilder() *Builder {
	return &Builder{resp: Response{}}
}

func (b *Builder) Code(code int) *Builder {
	b.resp.Code = code
	return b
}

func (b *Builder) Success(data interface{}) *Builder {
	b.resp.Code = 0
	b.resp.Message = "success"
	b.resp.Data = data
	return b
}

func (b *Builder) Error(msg string) *Builder {
	b.resp.Code = -1
	b.resp.Message = msg
	return b
}

func (b *Builder) Message(msg string) *Builder {
	b.resp.Message = msg
	return b
}

func (b *Builder) Data(data interface{}) *Builder {
	b.resp.Data = data
	return b
}

func (b *Builder) Build() Response {
	return b.resp
}
